#!/bin/bash
#========================================================================
# Author: YSLin
# Email: 
# File Name: ctrlflow.sh
# Description: 
#   1. if statement
#		if (expression1) {
#			action1
#		} else if (expression2) {
#			action2
#		} else {
#			action3
#		}
#   2. while statement
#		while (expression) {
#			actions
#		}
#   3. do statement
#		do {
#			actions
#		} while (expression)
#   4. for statement
# 		for (initialize_counter; test_counter; increment_counter) {
# 			action
# 		}


# Edit History: 
#   2010-12-24    File created.
#========================================================================
#1. if statement
awk '{
	printf "%s\t",$0;
	if ( $2 ~ /\$[1-9][0-9]*\.[0-9][0-9]/ ) {
		printf " * ";
		if ( $3 <= 75 ) {
			printf "REORDER\n" ;
		} else {
			printf "\n" ;
		}
	} else {
		if ( $3 < 75 ) {
			printf " REORDER\n" ;
		} else {
			printf "\n" ;
		}
	}
}' fruit_prices.txt ;


#2. while statement
awk 'BEGIN{ x=0 ; while (x < 5) { x+=1 ; print x ; } }' fruit_prices.txt

#3. do statement
awk 'BEGIN{ x=0 ; do { x+=1 ; print x ; } while (x < 5) }'

#4. for statement
awk '{
	for (x=1;x<=NF;x+=1) {
		printf "%s ",$x ;
	}
	printf "\n" ;
}' fruit_prices.txt

